<template>
  <dt-modal-edit
    ref="edit"
    :title="title"
    :loading="loading"
    :label-width="100"
    okText="保存"
    :width="800"
    @ok="onOk"></dt-modal-edit>
</template>

<script>
  import editOpt from '../opt/edit'
  import activityMgr from '@/biz/customerForCode/activity'
  export default {
    data() {
      return {
        loading: false,
        title: '新建/编辑活动',
        info: {},
        isEdit: false
      }
    },
    methods: {
      show(data) {
        this.isEdit = data.isEdit
        this.title = data.title
        this.info = {
          activityName: '',
          channelId: '',
          ...data
        }
        this.$refs.edit.show()
        this.$refs.edit.show(editOpt.options(this), this.info)
      },
      addChannel() {
        this.$router.push({
          name: 'buildingConfigure',
          params: {
            fromCustomer: 'caseChannelList'
          }
        })
      },

      onOk(data) {
        let params = {
          activityName: data.activityName,
          buildingId: this.$dt.buildInfo().housesId,
          channelId: data.channelId
        }
        if (data.activityId) {
          params.activityId = data.activityId
          activityMgr.update(params).then((res) => {
            this.$Message.success('保存成功')
            this.$emit('success')
            this.$refs.edit.hide()
          })
        } else {
          activityMgr.create(params).then((res) => {
            this.$Message.success('保存成功')
            this.$emit('success')
            this.$refs.edit.hide()
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped></style>
